package com.duobaoyu.dby.supply.biz.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * Created by shuming on 2023/10/10 15:12
 */
public final class ConverterUtils {
    public static String toJsonString(Object object) {
        if (Objects.isNull(object)) {
            return null;
        }
        return JSON.toJSONString(object);
    }

    public static <T> T parseObject(String json, Class<T> clazz, Feature... features) {
        if (StringUtils.isNotBlank(json)) {
            return JSON.parseObject(json, clazz, features);
        }
        return null;
    }

    public static <T> T parseObject(String json, TypeReference<T> type, Feature... features) {
        if (StringUtils.isNotBlank(json)) {
            return JSON.parseObject(json, type, features);
        }
        return null;
    }
}
